package fileoIO;

import java.io.*;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Demo2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入目标地址:");
        String srcPath = scanner.next();
        File srcFile = new File(srcPath);
        if(!srcFile.isFile()){
            System.out.println("文件不存在!");
            return ;
        }
        System.out.println("请输入目的地址:");
        String destPath = scanner.next();
        File destFile = new File(destPath);
        if(!destFile.getParentFile().isFile()){
            System.out.println("目的地址不正确!");
            return ;
        }

        try(InputStream inputStream = new FileInputStream(srcFile);
            OutputStream outputStream = new FileOutputStream(destFile)){
            while(true) {
                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if (n == -1) {
                    break;
                }
                outputStream.write(bytes,0,n);
            }
        }catch (IOException e){
            throw new RuntimeException();
        }
    }
}
